package com.example.emergencyattempt01.activity.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.viewpager.widget.PagerAdapter;
import com.example.emergencyattempt01.R;

import java.util.ArrayList;
import java.util.List;

public class AutoPager_Adapter extends PagerAdapter {

    List<Bitmap> bitmapsForDisplay;
    Context context;
    List<View> picViewsLittleContainer;
    public  AutoPager_Adapter(Context context,List<Bitmap> bitmapsForDisplay)
    {
        this.context=context;
        this.bitmapsForDisplay=bitmapsForDisplay;
        picViewsLittleContainer=new ArrayList<>();
        for(int i=0;i<bitmapsForDisplay.size();i++)
        {
            View view= LayoutInflater.from(context).inflate(R.layout.main_page_pic_container,null);
            ImageView imageView=view.findViewById(R.id.image_is_here);
            imageView.setImageBitmap(bitmapsForDisplay.get(i));
            picViewsLittleContainer.add(view);
        }
    }
    @Override
    public int getCount() {
        return bitmapsForDisplay.size();
    }

    @Override
    public boolean isViewFromObject(View view,Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(picViewsLittleContainer.get(position));
        return  picViewsLittleContainer.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position,Object object) {
        container.removeView(picViewsLittleContainer.get(position));
    }
}
